<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="css/style.css" rel="stylesheet" type="text/css"/>
    <script src="js/jquery-1.8.2.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="js/jquery.params.js"></script>
    <script type="text/javascript">
        var fixLogId=$.query.get("fixLogId");
        $.ajax({
            url:'admin/stock/findFixLogByID',
            data:JSON.stringify(fixLogId),
            type:'POST',
            dataType:'json',
            /*
           声明参数位json类型，便于后台接收时可以识别
            */
            headers:{
                Accept:"application/json",
                "Content-Type":"application/json"
            },
            processData:false,
            cache:false
        }).done(function (data) {
            printFixingLogInfo(data.fixlog[0]);
        });
        function printFixingLogInfo(fixlog) {
            var fixingLogTable="<input type='hidden' name='id' value='"+fixLogId+"'>" +
                "                <li><label>产品名</label><input  name='productname' readonly=\"readonly\"\n" +
                "                                             value=\""+fixlog.productname+"\" type=\"text\" class=\"dfinput\"/><i></i></li>\n" +
                "                <li><label>报修原因</label><input type=\"text\" readonly=\"readonly\" value=\""+fixlog.reason+" \"\n" +
                "                                              class=\"dfinput\"/><i></i></li>\n" +
                "                <li><label>客户姓名</label><input readonly=\"readonly\" type=\"text\"\n" +
                "                                              value=\""+fixlog.customername+"\" class=\"dfinput\"/><i></i></li>\n" +
                "                <li><label>联系电话</label><input name='customerphone' readonly=\"readonly\" type=\"number\" value=\""+fixlog.customerphone+"\"\n" +
                "                                              class=\"dfinput\"/><i></i></li>\n" +
                "                <li><label>客户地址</label><textarea readonly=\"readonly\" cols=\"\" rows=\"\"\n" +
                "                                                 class=\"textinput\">"+fixlog.customeraddress+"</textarea></li>\n" +
                "                <li><label>维修人</label>\n" +
                "                    <input type=\"text\" readonly=\"readonly\" value=\""+fixlog.workername+"\" class=\"dfinput\"/>\n" +
                "                    <i></i></li>\n" +
                "                <li><label>工号</label>\n" +
                "                    <input type=\"text\" name='username' readonly=\"readonly\" value=\""+fixlog.username+"\" class=\"dfinput\"/>\n" +
                "                    <i></i></li>\n" +
                "                <li><label>工作时长</label>\n" +
                "                    <input type=\"text\" readonly=\"readonly\" value=\""+new Date(fixlog.borrowtime).toLocaleString()+"至"+new Date(fixlog.returntime).toLocaleString()+"\"\n" +
                "                           class=\"dfinput\"/>\n" +
                "                    <i></i></li>\n" +
                "                <li><label>使用工具</label>\n" +
                "                    <input type=\"text\" readonly=\"readonly\" value=\""+fixlog.toolname+"-"+fixlog.toolcount+"个\"\n" +
                "                           class=\"dfinput\"/>\n" +
                "                    <i></i></li>\n" +
                "                <li><label>带走配件</label>\n" +
                "                    <input type=\"text\" readonly=\"readonly\" value=\""+fixlog.partsname+"-"+fixlog.partscount+"个\"\n" +
                "                           class=\"dfinput\"/>\n" +
                "                    <i></i></li>\n" +
                "                <li><label>入库旧件</label>\n" +
                "                    <input type=\"text\" readonly=\"readonly\" value=\""+fixlog.oldparts+"-"+fixlog.opcount+"个\"\n" +
                "                           class=\"dfinput\"/>\n" +
                "                    <i></i></li>\n" +
                "                <li><label>具体原因</label><input name=\"reason\" type=\"text\"\n" +
                "                                              class=\"dfinput\"/><i></i></li>\n" +
                "                <li><label>工人奖金</label><input name=\"bonus\" type=\"number\" min=\"0\"\n" +
                "                                              class=\"dfinput\"/><i></i></li>\n" +
                "                <li><label>维修费用</label><input name=\"cost\" value=\"0\" type=\"number\" min=\"0\"\n" +
                "                                              class=\"dfinput\"/><i></i></li>\n" +
                "                <li><label>是否修好</label><cite><input name=\"state\" type=\"radio\" value=\"1\" checked=\"checked\"/>已修好&nbsp;&nbsp;&nbsp;\n" +
                "                    &nbsp;<input name=\"state\" type=\"radio\" value=\"0\"/>未修好</cite></li>\n" +
                "                <li><label>&nbsp;</label><input type=\"button\" onclick='fixingToFixed();' class=\"btn\" value=\"确认\"/></li>";
            $("#fixingLogTable").html(fixingLogTable);
        }
    </script>
</head>


<div class="place">

    <div class="formbody">
        <form id="fixingLogForm">
            <div class="formtitle"><span>报修信息</span></div>
            <ul class="forminfo" id="fixingLogTable">

            </ul>

        </form>
    </div>
</div>
<script type="text/javascript">
    function fixingToFixed() {
        var params = $("#fixingLogForm").serializeArray();
        var fixingLog={};
        for (var item in params) {
            fixingLog[params[item].name] = params[item].value;
            if (fixingLog.cost==""||fixingLog.bonus==""||fixingLog.reason==""){
                switch (params[item].name) {
                    case 'cost':alert("维修费用不可为空！");break;
                    case 'bonus':alert("工人奖金不可为空！");break;
                    case 'reason':alert("具体原因不可为空！");break;
                }
                return;
            }
        }
         //alert(JSON.stringify(fixingLog));
        $.ajax({
            url:'/infoadmin/fixlog/fixingLogToFixedLog',
            data:JSON.stringify(fixingLog),
            type:'POST',
            dataType:'json',
            /*
           声明参数位json类型，便于后台接收时可以识别
            */
            headers:{
                Accept:"application/json",
                "Content-Type":"application/json"
            },
            processData:false,
            cache:false
        }).done(function (data) {
            alert("记录已生成，即将跳转至维修完成纪录列表");
            window.location.href="/fixloged.html";
        });
 }
</script>
</html>